package com.wsh.sms.service;

import com.wsh.sms.entity.Account;
import com.wsh.sms.mapper.AccountMapper;
import com.wsh.sms.utils.AccountExist;
import com.wsh.sms.utils.Result;
import com.wsh.sms.utils.ReturnResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author wsh
 */
@Service
public class AccountService {
    private final AccountMapper accountMapper;

    @Autowired
    public AccountService(AccountMapper accountMapper) {
        this.accountMapper = accountMapper;
    }

    /**
     * 通过用户名和密码查看是否具有权限
     * @param username is 用户名
     * @param password is 密码
     * @return 1 表示有， 0 表示没有
     */
    public String getAccountSuper(String username,String password){
        String result;
        if(accountMapper.getSuperAccess(username,password) == null) {
            return null;
        } else {
            result = accountMapper.getSuperAccess(username,password).getSuperAccess();
        }
        return result;
    }

    public String  existAccount(String username){
        String result;
        if(accountMapper.existAccount(username) == null){
            return AccountExist.NOT_EXIST.getExist();
        }
        else {
            result =  AccountExist.EXIST.getExist();
        }
        return result;
    }

    public int addCommonAccount(String username,String password){
        return accountMapper.addCommonAccount(username, password);
    }

    public String getNumber(String username){
        String number;
        if(accountMapper.existAccount(username) == null){
            return AccountExist.NOT_EXIST.getExist();
        }
        else {
            number =  accountMapper.existAccount(username).getNumber();
        }
        return number;
    }

    public int blindNumber(String number,String username){
        return accountMapper.blindNumber(number,username);
    }
}
